import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { VERSION_NEUTRAL, VersioningType } from '@nestjs/common';
import { TransformInterceptor } from 'src/common/interceptors/transform.interceptor';
import { AllExceptionsFilter } from 'src/common/exceptions/base.exception.filter';
import { HttpExceptionFilter } from 'src/common/exceptions/http.exception.filter';
import { generateDocument } from './doc';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  // 接口版本控制
  app.enableVersioning({
    defaultVersion: [VERSION_NEUTRAL],
    type: VersioningType.URI,
  });
  // 统一接口返回格式
  app.useGlobalInterceptors(new TransformInterceptor());
  // 全局异常处理以及自定义网络错误处理
  app.useGlobalFilters(new AllExceptionsFilter(), new HttpExceptionFilter());
  // swagger文档
  generateDocument(app);
  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
